#include "EditorComponentPropertyViewModel.h"

#include "Asset/EditorDefaultPackage.h"

#include "EditorComponentPropertyModel.h"
#include "Scene/SceneNodeComponent.h"

#include "Framework/Editor.h"

#include "Property/ReflectedProperty/EditorReflectedPropertyViewModel.h"
#include "Property/ReflectedProperty/EditorReflectedPropertyModel.h"

#include "Scene/SceneNodeComponent.h"
#include "Ability/ObjectProperty/EditorObjectPropertyAbilityViewModel.h"

void REditorComponentPropertyViewModel::BindModel(TSharedObjectPtr<REditorPropertyModel> InModel
        ,TSharedObjectPtr<REditorObjectPropertyAbilityViewModel> InAbilityViewModel)
{
    Super::BindModel(InModel,InAbilityViewModel);
    ComponentModel = InModel;

    ExpandedIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconChevronDown");
    CollapsedIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconChevronRight");

    Properties = NewObject<REditorReflectedPropertyViewModel>(this);
    Properties->BindModel(ComponentModel->Properties, InAbilityViewModel);
}

void REditorComponentPropertyViewModel::ToggleExpand()
{
    ComponentModel->bIsExpanded = !ComponentModel->bIsExpanded;
}

TSharedObjectPtr<RTexture2D> REditorComponentPropertyViewModel::GetExpandIcon() const
{
    return ComponentModel->bIsExpanded ? ExpandedIcon : CollapsedIcon;
}

bool REditorComponentPropertyViewModel::IsExpand() const
{
    return ComponentModel->bIsExpanded;
}

ECheckBoxWidgetState REditorComponentPropertyViewModel::GetAutoBeginPlayState() const
{
    return ComponentModel->Component->bAutoBeginPlay
        ? ECheckBoxWidgetState::Checked : ECheckBoxWidgetState::Unchecked;
}

void REditorComponentPropertyViewModel::ToggleAutoBeginPlay()
{
    ComponentModel->Component->bAutoBeginPlay
        = !ComponentModel->Component->bAutoBeginPlay;
}

CString REditorComponentPropertyViewModel::GetName() const
{
    return ComponentModel->Component->GetClass()->GetShortName();
}

void REditorComponentPropertyViewModel::RemoveComponent()
{
    AbilityViewModel->RemoveComponent(ComponentModel->Component);
}

TSharedObjectPtr<REditorReflectedPropertyViewModel> REditorComponentPropertyViewModel::GetProperties() const
{
    return Properties;
}
